package com.wandian.games.adapter;

import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.component.dly.xzzq_ywsdk.YwSDK;
import com.component.dly.xzzq_ywsdk.YwSDK_WebActivity;
import com.duoyou.task.openapi.DyAdApi;
import com.mylib.libcore.AppContext;
import com.mylib.libcore.utils.GlideUtil;
import com.mylib.libcore.utils.DevicesIDUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.games.R;
import com.wandian.games.bean.ToDayGameDataBean;
import com.xianwan.sdklibrary.helper.XWADPage;
import com.xianwan.sdklibrary.helper.XWADPageConfig;

import static com.mylib.libcore.config.AppSPKeyConfig.APP_OA_ID;

/**
 * @author Administrator
 * @date 2019/12/16-13:32
 * @description TodayTaskRecycleAdapter
 **/
public class TodayTaskRecycleAdapter extends BaseQuickAdapter<ToDayGameDataBean, BaseViewHolder> {

    public TodayTaskRecycleAdapter(int layoutResId) {
        super(layoutResId);
    }


    @Override
    protected void convert(BaseViewHolder helper, ToDayGameDataBean item) {
        ImageView iv_ad_pic = helper.getView(R.id.iv_ad_pic);
        TextView tv_go_do = helper.getView(R.id.tv_go_do);
        TextView tv_tj = helper.getView(R.id.tv_tj);
        TextView tv_jl = helper.getView(R.id.tv_jl);
        tv_jl.setText(item.getGameJL()+"");
        if(!UIUtils.isEmpty(item.getGameTJ())){
            tv_tj.setText(item.getGameTJ());
        }
        TextView tv_game_describe = helper.getView(R.id.tv_game_describe);
        TextView tv_game_name = helper.getView(R.id.tv_game_name);
        tv_game_name.setText(item.getGameName()+"");
        tv_game_describe.setText(item.getGameDescribe()+"");
        GlideUtil.into(mContext,item.getGamelogo(),iv_ad_pic);

        tv_go_do.setOnClickListener(v -> {
            if(item.getGameType().equals("DUOYOU")){
                DyAdApi.getDyAdApi().jumpAdDetail(mContext, AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"), item.getGameId());
            }
            if(item.getGameType().equals("XW")){
                XWADPage.jumpToAD(new XWADPageConfig.Builder( AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"))
                        .pageType(XWADPageConfig.PAGE_AD_DETAIL)
                        .msaOAID(DevicesIDUtil.getOaid())//指的是接入了安全联盟sdk后，获取的用户的oaid，获取不到可不用设置 或者传 空/null 不可乱传
                        .advertID( item.getGameId())//广告id 一般有api列表获取
                        .build());

            }

            if(item.getGameType().equals("YWHZ")){
            //传入广告id，直接进入广告的详情页
              //  YwSDK_WebActivity.Companion.open(mContext,item.getGameId());
                String oa_id = AppContext.getInstance().getAppPreferenceForever().getAppOAID();
                YwSDK.Companion.refreshMediaUserId(AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"));
                if(UIUtils.isEmpty(oa_id)){
                    YwSDK.Companion.refreshOaid(DevicesIDUtil.getDeviceIDAll(mContext));
                }else {
                    YwSDK.Companion.refreshOaid(oa_id+ "");
                }
                YwSDK_WebActivity.Companion.open(mContext,item.getGameId(),3);
                //进入详情页之前可以调用一下checkInit函数，确保初始化正常完成，该函数返回一个boolean对象
                YwSDK.Companion.checkInit();
                Log.d("getYWHZList","oaid="+oa_id);

            }

        });

        RelativeLayout rl_item =  helper.getView(R.id.rl_item);
        rl_item.setOnClickListener(v -> {
            if(item.getGameType().equals("DUOYOU")){
                DyAdApi.getDyAdApi().jumpAdDetail(mContext, AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"), item.getGameId());
            }
            if(item.getGameType().equals("XW")){
                XWADPage.jumpToAD(new XWADPageConfig.Builder( AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"))
                        .pageType(XWADPageConfig.PAGE_AD_DETAIL)
                        .msaOAID(DevicesIDUtil.getOaid())//指的是接入了安全联盟sdk后，获取的用户的oaid，获取不到可不用设置 或者传 空/null 不可乱传
                        .advertID( item.getGameId())//广告id 一般有api列表获取
                        .build());

            }

            if(item.getGameType().equals("YWHZ")){
                //传入广告id，直接进入广告的详情页
                String oa_id = AppContext.getInstance().getAppPreferenceForever().getAppOAID();
                YwSDK.Companion.refreshMediaUserId(AppContext.getInstance().getAppPreferencesHelper().getKeyValue("user_id"));
                if(UIUtils.isEmpty(oa_id)){
                    YwSDK.Companion.refreshOaid(DevicesIDUtil.getDeviceIDAll(mContext));
                }else {
                    YwSDK.Companion.refreshOaid(oa_id+ "");
                }
                //  YwSDK_WebActivity.Companion.open(mContext,item.getGameId());
                YwSDK_WebActivity.Companion.open(mContext,item.getGameId(),3);
                YwSDK.Companion.checkInit();
            }

        });
    }

}
